﻿using System;
using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    public class GUIContentAndGUIStyleExample : EditorWindow
    {
        [MenuItem("EditorExtensions/02_IMGUI/02_GUIContent And GUIStyle")]
        static void Open()
        {
            GetWindow<GUIContentAndGUIStyleExample>().Show();
        }
        
        enum Mode
        {
            GUIContent,
            GUIStyle
        }

        private int mToolbarIndex = 0;
        private GUIStyle mBoxStyle = "box";
        private Lazy<GUIStyle> mFontStyle = new Lazy<GUIStyle>(() =>
        {
            var retStyle = new GUIStyle("label");
            retStyle.fontSize = 30;
            retStyle.fontStyle = FontStyle.BoldAndItalic;
            
            // 颜色
            retStyle.normal.textColor = Color.green;
            retStyle.hover.textColor = Color.blue;
            retStyle.focused.textColor = Color.red;
            retStyle.active.textColor = Color.cyan;
            retStyle.normal.background = Texture2D.whiteTexture;
            return retStyle;
        });
        
        private Lazy<GUIStyle> mButtonStyle = new Lazy<GUIStyle>(() =>
        {
            var retStyle = new GUIStyle(GUI.skin.button);
            retStyle.fontSize = 30;
            retStyle.fontStyle = FontStyle.BoldAndItalic;
            
            // 颜色
            retStyle.normal.textColor = Color.green;
            retStyle.hover.textColor = Color.blue;
            retStyle.focused.textColor = Color.red;
            retStyle.active.textColor = Color.cyan;
            retStyle.normal.background = Texture2D.whiteTexture;
            return retStyle;
        });
        
        private void OnGUI()
        {
            mToolbarIndex = GUILayout.Toolbar(mToolbarIndex, Enum.GetNames(typeof(Mode)));

            switch ((Mode)mToolbarIndex)
            {
                case Mode.GUIContent:
                    GUILayout.Label("把鼠标放在我身上");
                    GUILayout.Label(new GUIContent("把鼠标放在我身上"));
                    GUILayout.Label(new GUIContent("把鼠标放在我身上", "已经正确放置"));
                    GUILayout.Label(new GUIContent("把鼠标放在我身上", Texture2D.whiteTexture));
                    GUILayout.Label(new GUIContent("把鼠标放在我身上", Texture2D.whiteTexture,"已经正确放置"));
                    break;
                
                case Mode.GUIStyle:
                    GUILayout.Label("Style of default");
                    GUILayout.Label("Style of box", mBoxStyle);
                    GUILayout.Label("Style font", mFontStyle.Value);
                    if (GUILayout.Button("Button font", mButtonStyle.Value))
                    {
                        Debug.Log("Button font");
                    }
                    break;
            }
        }
    }
}